#coding=utf-8
import wx

class MainToolBar(wx.ToolBar):
    def __init__(self, parent):
        wx.ToolBar.__init__(self, parent, -1, style=( wx.TB_HORIZONTAL| wx.NO_BORDER| wx.TB_FLAT))
        self.parent=parent

        tsize = (16,16)
        new_bmp =  wx.ArtProvider.GetBitmap(wx.ART_NEW, wx.ART_TOOLBAR, tsize)
        open_bmp = wx.ArtProvider.GetBitmap(wx.ART_FILE_OPEN, wx.ART_TOOLBAR, tsize)
        copy_bmp = wx.ArtProvider.GetBitmap(wx.ART_COPY, wx.ART_TOOLBAR, tsize)
        paste_bmp= wx.ArtProvider.GetBitmap(wx.ART_PASTE, wx.ART_TOOLBAR, tsize)
        quit_bmp= wx.ArtProvider.GetBitmap(wx.ART_QUIT, wx.ART_TOOLBAR, tsize)

        self.SetToolBitmapSize(tsize)
        
        self.AddLabelTool(10, "New", new_bmp, shortHelp=u"上传新文件", longHelp="Long help for 'New'")
        parent.Bind(wx.EVT_TOOL, self.OnToolClick, id=10)

        self.AddLabelTool(20, "Open", open_bmp, shortHelp="Open", longHelp="Long help for 'Open'")
        parent.Bind(wx.EVT_TOOL, self.OnToolClick, id=20)

        self.AddSeparator()
        self.AddSimpleTool(30, copy_bmp, "Copy", "Long help for 'Copy'")
        parent.Bind(wx.EVT_TOOL, self.OnToolClick, id=30)

        self.AddSimpleTool(40, paste_bmp, "Paste", "Long help for 'Paste'")
        parent.Bind(wx.EVT_TOOL, self.OnToolClick, id=40)

        parent.Bind(wx.EVT_TOOL_ENTER, self.OnToolEnter)
        parent.Bind(wx.EVT_TOOL_RCLICKED, self.OnToolRClick) # Match all
        parent.Bind(wx.EVT_TIMER, self.OnClearSB)

        cbID = wx.NewId()
        self.AddControl(
            wx.StaticText(
                self, cbID, u"  查找关键字: "  
#                style=wx.CB_DROPDOWN
                ))
        
        cbID = wx.NewId()
        self.AddControl(
            wx.ComboBox(
                self, cbID, "", choices=["","abc"], 
                size=(100,-1), style=wx.CB_DROPDOWN
                ))
        parent.Bind(wx.EVT_COMBOBOX, self.OnCombo, id=cbID)

        self.AddSeparator()

        self.AddSimpleTool(50, quit_bmp, u"退出", "Long help for 'Quit'")
        parent.Bind(wx.EVT_TOOL, self.OnToolClick, id=50)

        self.Realize()


    def DoSearch(self,  text):
        print "DoSearch: %s\n" % text
        return True

    def OnToolClick(self, event):  #工具栏事件处理
        id=event.GetId()
        if id==10:
            self.parent.listbook.OnPopupThree(event)
            print u"tool 上传文件 ==> %s clicked\n" % id
        elif id==50:
            self.parent.OnCloseWindow(event)
            print u"tool 退出程序 ==> %s clicked\n" % id
        else:
            print u"tool ==> %s clicked\n" % id
        
    def OnToolRClick(self, event):
        print u"tool %s right-clicked\n" % event.GetId()

    def OnCombo(self, event):
        print u"combobox item selected: %s\n" % event.GetString()

    def OnToolEnter(self, event):
        print u'OnToolEnter: %s, %s\n' % (event.GetId(), event.GetInt())


    def OnClearSB(self, event):  # called for the timer event handler
        self.SetStatusText("")
    
if __name__=='__main__':
    import pocketdisk
